package com.voilet.interview.rx.operator.filter;

import android.util.Log;

import com.voilet.interview.rx.operator.absOperator;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

/**
 * Created by kan212 on 2019/4/10.
 */

public class skip implements absOperator {
    @Override
    public void test() {
        Observable.just(1,2,3,4,5)
                // 跳过正序的前1项
                .skip(1)
                // 跳过正序的后2项
                .skipLast(2)
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        Log.d(TAG,"获取到的整型事件元素是： "+ integer);
                    }
                });

    }

    @Override
    public void test2() {
        // 使用2：根据时间跳过数据项
        // 发送事件特点：发送数据0-5，每隔1s发送一次，每次递增1；第1次发送延迟0s
        Observable.intervalRange(0, 5, 0, 1, TimeUnit.SECONDS)
                .skip(1, TimeUnit.SECONDS) // 跳过第1s发送的数据
                .skipLast(1, TimeUnit.SECONDS) // 跳过最后1s发送的数据
                .subscribe(new Consumer<Long>() {

                    @Override
                    public void accept( Long along ) throws Exception {
                        Log.d(TAG,"获取到的整型事件元素是： "+ along);
                    }
                });
    }
}
